package com.achievement.controller;

import com.achievement.domain.dto.AllProjectDTO;
import com.achievement.domain.dto.ProjectProductDTO;
import com.achievement.domain.dto.UpdateProjectProductDTO;
import com.achievement.domain.vo.AllProjectVO;
import com.achievement.service.IAllProjectService;
import com.achievement.service.IProjectProductService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * RelyProjectController
 * 成果管理，科研成果，成果依托项目
 */


@RestController
@RequestMapping("/achievement/relyProject")
@Api(tags = "成果管理模块---成果依托项目")
public class RelyProjectController extends BaseController {

    @Autowired
    private IProjectProductService projectProductService;

    @Autowired
    private IAllProjectService allProjectService;

    /**
     * 新增或者编辑保存成果依托项目关系
     */
//    @PreAuthorize("@ss.hasPermi('achievement:relyproject:add')")
    @Log(title = "新增或者编辑保存成果依托项目关系", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save")
    @ApiOperation(value = "新增或者编辑保存成果依托项目关系", notes = "新增或者编辑保存成果依托项目关系")
    public AjaxResult save(@RequestBody UpdateProjectProductDTO dto) {
        return toAjax(projectProductService.save(dto));
    }

//    @PreAuthorize("@ss.hasPermi('achievement:relyproject:get')")
    @GetMapping("/getByProductId/{id}")
    @ApiOperation(value = "根据成果id查询成果依托项目列表", notes = "根据成果id查询成果依托项目列表")
    public AjaxResult list(@PathVariable(value = "id") String id) {
        List<AllProjectVO> list = allProjectService.selectByProductId(id);
        return success(list);
    }

//    @PreAuthorize("@ss.hasPermi('achievement:relyproject:list')")
    @PostMapping("/getProjectByUser")
    @ApiOperation(value = "根据负责人id和项目状态查询个人项目列表", notes = "根据负责人id和项目状态查询个人项目列表")
    public AjaxResult getProjectByUser(@RequestBody AllProjectDTO dto) {
        List<AllProjectVO> list = allProjectService.getProjectByUser(dto);
        return success(list);
    }

}
